// 云函数入口文件
const cloud = require('wx-server-sdk')
const got = require('got');

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async(event, context) => {
  let grantType = 'client_credentials'
  let apiKey = 'kL6WoMYT5zPZBGT6K55oEeGe'
  let secretKey = 'Rpb8KFftSfxfAu5CP4MNkI8e1y4EfBl7'
  let url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=' + grantType + '&client_id=' + apiKey + '&client_secret=' + secretKey
  let getResponse = await got(url)
  let responseJson = JSON.parse(getResponse.body);
  return responseJson
}